<template>
  <div class="container mx-auto px-4 py-12 max-w-3xl bg-gradient-to-br from-white to-gray-50 min-h-screen">
    <header class="mb-10 text-center">
      <h1 class="text-4xl md:text-5xl font-bold bg-clip-text text-transparent bg-gradient-to-r from-blue-600 to-purple-600 mb-2 transition-all duration-300 hover:scale-105">Markdown UI Example</h1>
      <p class="text-gray-500 text-lg">一个现代化的Markdown交互演示</p>
    </header>
    
    <main class="bg-white rounded-xl shadow-lg p-6 md:p-8 mb-6 transition-all duration-300 hover:shadow-xl border border-gray-100">
      <MarkdownUI :html="html" @widgetEvent="handleWidgetEvent" :theme="'light'" />
    </main>
    
    <transition name="fade-in-up">
      <div v-if="userName" class="mt-6 p-5 bg-gradient-to-r from-blue-50 to-indigo-50 rounded-xl text-xl font-semibold text-gray-800 shadow-md border border-blue-100 transform transition-all duration-500 hover:translate-y-[-2px]">
        你好，<span class="text-blue-600">{{ userName }}</span> 👋
      </div>
    </transition>
  </div>
</template>

<script setup>
import { MarkdownUI } from '@markdown-ui/vue'
import '@markdown-ui/vue/widgets.css'
import { Marked } from 'marked'
import { markedUiExtension } from '@markdown-ui/marked-ext'
import { ref } from 'vue'

// 用户名字状态
const userName = ref('')

const marked = new Marked()
marked.use(markedUiExtension)

const markdown = `
\`\`\`markdown-ui-widget
text-input username "请输入您的名字" "名字"
\`\`\`
`

const html = marked.parse(markdown)

const handleWidgetEvent = (event) => {
  console.log(`用户名字: ${event.detail.value}`)
  userName.value = event.detail.value
}
</script>

<style scoped>
/* 使用Tailwind CSS类替代内联样式，保留必要的深度选择器 */
.container :deep(.markdown-ui) {
  background-color: inherit;
  color: inherit;
}

.container :deep(input) {
  @apply bg-white text-gray-800 border border-gray-300 rounded-lg px-4 py-3 text-lg shadow-sm focus:outline-none focus:ring-3 focus:ring-blue-500 focus:border-blue-500 transition-all duration-300 placeholder-gray-400 w-full max-w-md;
}

.container :deep(input:hover) {
  @apply border-gray-400;
}

/* 动画过渡效果 */
.fade-in-up-enter-active,
.fade-in-up-leave-active {
  @apply transition-all duration-500 ease-out;
}

.fade-in-up-enter-from,
.fade-in-up-leave-to {
  @apply opacity-0 transform translate-y-4;
}
</style>